package org.springblade.modules.notice.enums.placeholder;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springblade.modules.notice.constant.AbarbeitungVariableConstant;
import org.springblade.modules.notice.constant.RepairVariableConstant;
import org.springblade.modules.notice.vo.CommonEnumInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author ysq
 * @Date 2024/11/21
 * @Description 整改变量
 */
@Getter
@AllArgsConstructor
public enum AbarbeitungVariable implements VariableEnum {

	PLAN_ID(0, "planId", "工单ID", true, AbarbeitungVariableConstant.WORKER_INFO),

	PROJECT_NAME(1, "projectName", "项目名称", true, AbarbeitungVariableConstant.WORKER_INFO),

	ELEVATOR_NAME(2, "elevatorAddress", "电梯名称", true, AbarbeitungVariableConstant.WORKER_INFO),

	SCORE_ISSUE(3, "scoreIssue", "问题数量", true, AbarbeitungVariableConstant.WORKER_EXT_INFO),

	ELEVATOR_ID(4, "elevatorId", "电梯ID", true, AbarbeitungVariableConstant.WORKER_INFO),

	ESTIMATED_END_TIME(5, "estimatedEndTime", "整改期限", true, AbarbeitungVariableConstant.WORKER_INFO),

	EXECUTOR(6, "executor", "任务执行人", true, AbarbeitungVariableConstant.EXECUTOR),

	CREATE_TIME(7, "createTime", "工单创建时间", true, AbarbeitungVariableConstant.WORKER_INFO),

	PLAN_DATE(18, "planDate", "计划日期", true, AbarbeitungVariableConstant.WORKER_INFO),

	PLAN_END_TIME(20, "planEndTime", "工单完成时间", true, AbarbeitungVariableConstant.WORKER_EXT_INFO),

	;

	/**
	 * 编码
	 */
	private final Integer code;

	/**
	 * 变量名称
	 */
	private final String var;

	/**
	 * 描述
	 */
	private final String desc;

	/**
	 * 是否显示
	 */
	private final Boolean isShow;

	/**
	 * sql
	 */
	private final String sql;

	/**
	 * 获取可选列表
	 * @return 可选列表
	 */
	public static List<CommonEnumInfo> getSelectList() {
		List<CommonEnumInfo> list = new ArrayList<>(16);
		for (AbarbeitungVariable value : AbarbeitungVariable.values()) {
			if (value.isShow) {
				list.add(new CommonEnumInfo(value.getCode(), String.format("%s: ${%s}", value.getDesc(), value.getVar())));
			}
		}
		return list;
	}

	/**
	 * 根据code获取变量名
	 * @param code
	 * @return
	 */
	public static String getVarByCode(Integer code) {
		for (AbarbeitungVariable value : AbarbeitungVariable.values()) {
			if (value.getCode().equals(code)) {
				return value.getVar();
			}
		}
		return null;
	}

	/**
	 * 根据变量名获取code
	 * @param var
	 * @return
	 */
	public static Integer getCodeByVar(String var) {
		for (AbarbeitungVariable value : AbarbeitungVariable.values()) {
			if (value.getVar().equals(var)) {
				return value.getCode();
			}
		}
		return null;
	}
}
